package com.bishe.bishe.Service.ServiceImpl;

import com.bishe.bishe.Service.TypesService;
import com.bishe.bishe.dao.mapper.TypesMapper;
import com.bishe.bishe.pojo.Types;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class TypesServiceImpl implements TypesService {

    @Autowired
    private TypesMapper typesMapper;
    @Override
    public List<Types> findall() {
        return typesMapper.findall();
    }

    @Override
    public int insert(String typeName) {
        return typesMapper.insert(typeName);
    }

    @Override
    public int delete(int typeId,int typeState) {
        return typesMapper.delete(typeId,typeState);
    }

    @Override
    public int update(Types types) {
        return typesMapper.update(types);
    }

    @Override
    public Types findTypes(int typeId) {
        return typesMapper.findTypes(typeId);
    }

    @Override
    public Types findTypesByName(String typeName) {
        return typesMapper.findByTypes(typeName);
    }

    @Override
    public PageInfo<Types> findPage(Map <String, Object> searchMap, int page, int size) {
        PageHelper.startPage(page,size);
        if (searchMap!=null){
            if (searchMap.get("name")!=null&&!"".equals(searchMap.get("name"))){
                return  new PageInfo<>(typesMapper.findByTypesList(searchMap.get("name").toString()));
            }else {
                return null;
            }
        }else {
            return null;
        }
    }
}
